package server.main.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import server.main.service.AccountService;
import server.main.service.CaptchaService;

import java.util.HashMap;
import java.util.Map;

@RequestMapping("/before")
@RestController
public class BeforeLoginController {


    @Autowired
    AccountService accountService;

    @Autowired
    CaptchaService captchaService;



    @RequestMapping("/getcaptcha")
    public Map<String,Object>imgCaptcha(){
        Map<String, Object> map = new HashMap<>(4);
        map.put("code", 0);
        map.put("msg", "获取成功");
        String captcha = captchaService.getCaptcha();
        map.put("data", captcha);
        return map;
    }
    @PostMapping("/register")
    public Map<String,Object> register(@RequestParam("jobnum") String jobnum,
                                       @RequestParam("password") String password
                                       ){
        Map<String ,Object> map = new HashMap<>();

        try{
            accountService.register(jobnum,password);
            map.put("code",200);
            map.put("msg","信息登记成功,正在跳转登录页面！");
        }catch (Exception e){
            map.put("code", 300);
            map.put("msg", e.getMessage());
        }

        return map;
    }


}
